//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package objects;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D.Float;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;

public class ForestsInstance {
    private final LinkedHashMap<Integer, ForestsInstanceEntry> forests = new LinkedHashMap();

    public ForestsInstance() {
    }

    public void addEntry(ForestsInstanceEntry e) {
        this.forests.put(Integer.valueOf(e.getInstanceId()), e);
    }

    public void removeEntry(ForestsInstanceEntry e) {
        this.forests.remove(Integer.valueOf(e.getInstanceId()));
    }

    public Collection<ForestsInstanceEntry> get() {
        return this.forests.values();
    }

    public void reset() {
        this.forests.clear();
    }

    public List<ForestsInstanceEntry> getForestsToRemove() {
        ArrayList val = new ArrayList();
        Float tilemap = this.getTileMap();
        Iterator var4 = this.forests.values().iterator();

        while(var4.hasNext()) {
            ForestsInstanceEntry e = (ForestsInstanceEntry)var4.next();
            if(e.isEntryInsidePath(tilemap)) {
                val.add(e);
            }
        }

        return val;
    }

    public LinkedHashMap<Integer, Integer> getToolsRequirement() {
        LinkedHashMap rval = new LinkedHashMap();
        List toremove = this.getForestsToRemove();

        ForestsInstanceEntry r;
        Integer count;
        for(Iterator var4 = toremove.iterator(); var4.hasNext(); rval.put(r.getToolId(), Integer.valueOf(count.intValue() + 1))) {
            r = (ForestsInstanceEntry)var4.next();
            count = (Integer)rval.get(r.getToolId());
            if(count == null) {
                count = Integer.valueOf(0);
            }
        }

        return rval;
    }

    private Float getTileMap() {
        byte x = -12;
        byte y = -2;
        byte width = 44;
        byte height = 35;
        Float path = new Float();
        path.moveTo((float)x, (float)y);
        path.lineTo((float)(x + width), (float)y);
        path.lineTo((float)(x + width), (float)(y + height));
        path.lineTo((float)x, (float)(y + height));
        path.closePath();
        return path;
    }

    public BufferedImage getForestImage(int scale) {
        Rectangle r = this.getTileMap().getBounds();
        BufferedImage f = new BufferedImage(r.width * scale, r.height * scale, 2);
        Float p = new Float();
        Iterator var6 = this.forests.values().iterator();

        while(var6.hasNext()) {
            ForestsInstanceEntry gc = (ForestsInstanceEntry)var6.next();
            if(gc.isEntryInsidePath(this.getTileMap())) {
                p.append(gc.getPath(scale), false);
            }
        }

        p.append(this.getTileMap(), false);
        Graphics2D gc1 = (Graphics2D)f.getGraphics();
        gc1.setColor(Color.black);
        gc1.setBackground(Color.white);
        gc1.setTransform(new AffineTransform(AffineTransform.getTranslateInstance((double)(-(r.x * scale)), (double)(-(r.y * scale)))));
        gc1.draw(p);
        return f;
    }
}
